<template>
  <div>
    <div class="pds-tip">
      <el-form :inline="true" :model="pageData.params" class="filter">
        <el-form-item>
          <el-input
            v-model="pageData.params.plmModelNo"
            placeholder="请输入机型号"
            width="200px"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search(pageData.params)">查询</el-button>
          <el-button type="danger" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table :data="tableData" border style=" margin: 15px auto;">
      <el-table-column width="50" align="center" label="序号">
        <template
          slot-scope="scope"
        >{{(pageData.params.page-1)*pageData.params.size+(scope.$index+1)}}</template>
      </el-table-column>
      <el-table-column prop="plmArticleNo" label="机型全码" align="center" width="100px"></el-table-column>
      <el-table-column prop="pdsConfCategory.nameCn" label="产品类别" align="center" width="180px"></el-table-column>
      <el-table-column prop="plmModelNo" label="机型号" align="center" width="180px"></el-table-column>
      <el-table-column prop="productName" label="产品名称" align="center"></el-table-column>
      <el-table-column prop="fullCost" label="全成本" align="center" width="100px"></el-table-column>
      <!-- <el-table-column width="" align="center" label="状态">
        <template slot-scope="scope">
          <span v-if="scope.row.status===0">草稿</span>
          <span v-if="scope.row.status===1">审核中</span>
          <span v-if="scope.row.status===2">已发布</span>
          <span v-if="scope.row.status===3">已删除</span>
        </template>
      </el-table-column>-->
      <el-table-column prop="createTime" label="查询时间" align="center" width="180px"></el-table-column>
      <el-table-column label="操作" align="center" width="220px">
        <template slot-scope="scope">
          <el-button type="primary" @click="getNew(scope.row.id)" size="small">获取最新</el-button>
          <el-button type="success" @click="showDetail(scope.row.id)" size="small">查看明细</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination :pageData="pageData.params" @pageChange="changePage" @changeSize="changeSize"></pagination>
    <!-- 查看详情弹框 -->
    <el-dialog :title="dialogTitle" :visible.sync="DialogVisible" width="75%" center>
      <el-table :data="tableData3" style="width: 100%">
        <el-table-column label="产品成本A" align="center">
          <el-table-column prop="bomCost" label="整机BOM国产成本(未税)" width="120"></el-table-column>
          <el-table-column prop="packageCost" label="包装成本(未税)" width="120"></el-table-column>
          <el-table-column prop="laborCost" label="人工成本" width="120"></el-table-column>
          <el-table-column prop="changeCost" label="变动制费" width="120"></el-table-column>
        </el-table-column>
        <el-table-column prop="productManufactureCost" label="产品制造成本(未税)" width="150"></el-table-column>
        <el-table-column label="进口料件成本F">
          <el-table-column prop="localCurrencyOperation" label="本币未税成本RMB(含操作费)" width="120"></el-table-column>
          <el-table-column prop="localCurrencyCost" label="本币未税成本RMB" width="120"></el-table-column>
          <el-table-column prop="originalCurrencyUsd" label="原币成本(美金)" width="120"></el-table-column>
          <el-table-column prop="originalCurrencyEur" label="原币成本(欧元)" width="120"></el-table-column>
          <el-table-column prop="originalCurrencyJpy" label="原币成本(日元)" width="120"></el-table-column>
          <el-table-column prop="originalCurrencyOther" label="原币成本(其他币种)" width="120"></el-table-column>
        </el-table-column>
        <el-table-column label="内陆运输成本D(变动)">
          <el-table-column prop="inlandFreight" label="内陆运费" width="120"></el-table-column>
        </el-table-column>
        <el-table-column label="产品项目开发费用B(变动)">
          <el-table-column prop="developmentCost" label="费用分摊(总费用/预计数量)" width="120"></el-table-column>
        </el-table-column>
        <el-table-column label="公司管理费用分摊C(固定)">
          <el-table-column label="费用管理分摊" width="120">
            <template slot-scope="scope">
              <span>{{scope.row.manageCost}} | {{scope.row.manageCostRate}}</span>
            </template>
          </el-table-column>
          <el-table-column label="制造费用分摊" width="120">
            <template slot-scope="scope">
              <span>{{scope.row.manufactureCost}} | {{scope.row.manufactureCostRate}}</span>
            </template>
          </el-table-column>
          <el-table-column label="研发费用分摊(新产品)" width="120">
            <template slot-scope="scope">
              <span>{{scope.row.researchCost}} | {{scope.row.researchCostRate}}</span>
            </template>
          </el-table-column>
          <el-table-column label="财务费用分摊" width="120">
            <template slot-scope="scope">
              <span>{{scope.row.financeCost}} | {{scope.row.financeCostRate}}</span>
            </template>
          </el-table-column>
          <el-table-column label="营销费用分摊" width="120">
            <template slot-scope="scope">
              <span>{{scope.row.marketingCost}} | {{scope.row.marketingCostRate}}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="抗风险系数E">
          <el-table-column label="风险变动比率" width="120">
            <template slot-scope="scope">
              <span>{{scope.row.riskChangeCost}} | {{scope.row.riskChangeRate}}</span>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="DialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import * as api from "@/api/product/cost/index";

export default {
  name: "requireStructure",
  data() {
    return {
      customerList: [],
      dialogTitle: "",
      DialogVisible: false,
      pageData: {
        params: {
          page: 1,
          size: 10,
          plmModelNo: "",
          total: ""
        }
      },
      tabName: "first",
      tableData: [],
      tableData1: [],
      tableData3: [
        {
          date: "2016-05-03",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333
        },
        {
          date: "2016-05-02",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333
        },
        {
          date: "2016-05-08",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333
        },
        {
          date: "2016-05-06",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333
        },
        {
          date: "2016-05-07",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333
        }
      ]
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    getList() {
      const params = this.pageData.params;
      api.getFullCostList(params).then(response => {
        if (response.code === 200) {
          this.tableData = response.data.rows;
          this.pageData.params.total = response.data.total;
        }
      });
    },
    search() {
      this.pageData.params.page = 1;
      this.getList();
    },
    changePage(pageData) {
      this.pageData.params.page = pageData.page;
      console.log(pageData);
      this.getList();
    },
    changeSize(pageSize) {
      this.pageData.params.size = pageSize;
      this.pageData.params.page = 1;
      this.getList();
    },
    reset() {
      this.pageData.params = {
        page: 1,
        size: 10,
        plmModelNo: ""
      };
      this.getList();
    },
    //查看明细
    showDetail(costId) {
      if (costId) {
        this.DialogVisible = true;
        this.dialogTitle = "查看明细";
        api.getDetail({ costId }).then(response => {
          if (response.code === 200) {
            this.tableData3 = response.data;
          }
        });
      }
    },
    //查看明细
    getNew(costId) {
      if (costId) {
        api.getNew({ fullCostId: costId }).then(response => {
          if (response.code === 200) {
            this.$message({
              type: "success",
              message: "更新成功!"
            });
            this.getList();
          }
        });
      }
    }
  }
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.bigbox {
  width: 100%;
  background: #f5f5f5;
  overflow: hidden;
}
.pds-tip-green .filter {
  padding-top: 29px !important;
}
.el-header,
.el-footer {
  width: 300px;
  background-color: #ffffff;
  color: #333;
  text-align: center;
  line-height: 60px;
  border: 1px solid #ccc;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  width: 300px;
  background-color: #fff;
  color: #333;
  text-align: center;
  line-height: 160px;
  margin-bottom: 30px;
  border: 1px solid #ccc;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}

.el-tabs__header {
  margin: 0;
}

.pds-tip-green {
  padding: 8px 16px;
  background-color: #f8f8f8;
  border-radius: 4px;
  border-left: 5px solid #42b983;
  margin: 0 0 20px;
  p {
    font-size: 14px;
    color: #5e6d82;
    line-height: 1.5em;
    margin-top: 5px;
    margin-bottom: 5px;
  }
}
</style>

